package com.mvd.app.ac2020;

import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.jph.takephoto.app.TakePhoto;
import com.jph.takephoto.app.TakePhotoActivity;
import com.jph.takephoto.model.TImage;
import com.jph.takephoto.model.TResult;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.mvd.app.R;
import com.mvd.app.ac2021.activitys.adapter.Wai_6M_PhotoAdapter;
import com.mvd.app.adapter.MyProvincesListAdapter2;
import com.mvd.app.api.ApiConfig;
import com.mvd.app.commons.CommonUtils;
import com.mvd.app.commons.Constants;
import com.mvd.app.commons.DateUtil;
import com.mvd.app.commons.PDALogUtils;
import com.mvd.app.commons.SharedPreferencesUtils;
import com.mvd.app.commons.SystemUtil;
import com.mvd.app.commons.UtilsLog;
import com.mvd.app.model.CarsInforModel;
import com.mvd.app.model.PictureModel;
import com.mvd.app.model.RecheckCarsModel;
import com.mvd.app.model.TypeModel;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import top.zibin.luban.Luban;
import top.zibin.luban.OnCompressListener;

import static com.mvd.app.application.BaseApplication.WAIJIAN_PHOTO_PREVIEW_LISTS;

/**
 * @author Administrator
 * @version V1.0
 * @Title: QingDaoPhotoActivity
 * @Package com.mvd.app.ac2021.activitys
 * @date 2020-12-28 13:44
 **/

public class QingDaoPhotoActivity extends TakePhotoActivity implements ApiConfig {

    @BindView(R.id.ac_6m_photo_ib_back_qingdao)
    ImageButton ac6mPhotoIbBack;
    @BindView(R.id.ac_6m_photo_title_txt_qingdao)
    TextView ac6mPhotoTitleTxt;
    @BindView(R.id.ac_6m_photo_listview_qingdao)
    ListView ac6mPhotoListview;
    @BindView(R.id.ac_6m_photo_btn_other_imags_qingdao)
    Button ac6mPhotoBtnOtherImags;
    @BindView(R.id.ac_6m_photo_btn_buhege2_qingdao)
    Button ac6mPhotoBtnBuhege2;
    @BindView(R.id.ac_6m_photo_btn_wancheng2_qingdao)
    Button ac6mPhotoBtnWancheng2;
    @BindView(R.id.ac_6m_photo_ll_bottom_layout_qingdao)
    LinearLayout ac6mPhotoLlBottomLayout;
    @BindView(R.id.ac_6m_photo_scrollview_qingdao)
    ScrollView ac6mPhotoScrollview;
    @BindView(R.id.ac_wai_6m_line_qingdao)
    TextView acWai6mLine;
    private QingDaoPhotoActivity instances = null;
    private String carNo = null, Line = "1";//车牌号码
    private String PHOTO_TYPE = "";//外检拍照的TYPE上传类型
    private String Item_Code = "F1";

    TakePhoto takePhoto;
    Uri imageUri;
    private CarsInforModel carsInforModel;
    private String Login_name, login_IDNumber;
    private RecheckCarsModel recheckCarsModel;
    int flag = 0;
    private String isYasuoPhoto;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        setContentView(R.layout.activity_qingdao);
        ButterKnife.bind(this);
        instances = this;
        isYasuoPhoto = SharedPreferencesUtils.getIsYasuoPhoto(instances);
        String logStr = "\n" + "青岛地区拍摄--照片--carsInforModel-" + "\n";
        PDALogUtils.createLogFile(0, logStr.getBytes());
        WAIJIAN_PHOTO_PREVIEW_LISTS = new HashMap<>();
        init();
        pop_xuhao();
        if (getIntent() != null) {
            Login_name = getIntent().getExtras().getString("login_w_name", "");
            login_IDNumber = getIntent().getExtras().getString("login_IDNumber", "");

            carsInforModel = (CarsInforModel) getIntent().getSerializableExtra("model_CarsInforModel");
            String logStr2 = "\n" + "青岛地区拍摄--照片--carsInforModel-" + "\n" +
                    "carsInforModel:" + "\n" + carsInforModel.toString() + "\n" +
                    "Login_name:" + Login_name + "\n" + "login_IDNumber:" + login_IDNumber + "\n" +
                    "line:" + Line + "\n";
            PDALogUtils.createLogFile(0, logStr2.getBytes());
            //车牌号码
            if (!TextUtils.isEmpty(carsInforModel.getPlateRegion()) &&
                    !TextUtils.isEmpty(carsInforModel.getPlateNO())) {
                carNo = carsInforModel.getPlateRegion() + carsInforModel.getPlateNO();
            }
            acWai6mLine.setText(Line);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
//        if (CommonUtils.isOnline(instances)) {
//        } else {
//            Toast.makeText(instances, getResources().getString(R.string.network_error), Toast
//                    .LENGTH_LONG).show();
//        }
    }


    Wai_6M_PhotoAdapter contentAdapter2;
    List<TypeModel> typeModelListAdapter = null;

    private void init() {
        typeModelListAdapter = new ArrayList<>();
        TypeModel typeModel = null;
        for (int i = 0; i < Constants.QIGNDAO_PHOTO_TYPE_LISTS.length; i++) {
            typeModel = new TypeModel();
            typeModel.setName(Constants.QIGNDAO_PHOTO_TYPE_LISTS[i][0] + "-" + Constants.QIGNDAO_PHOTO_TYPE_LISTS[i][1]);
            typeModel.setCode(Constants.QIGNDAO_PHOTO_TYPE_LISTS[i][1]);
            typeModelListAdapter.add(typeModel);
        }
        contentAdapter2 = new Wai_6M_PhotoAdapter(instances, typeModelListAdapter,
                mListener);
//        contentAdapter2 = new ContentAdapter2(instances, typeModelListAdapter,
//                mListener, instances, 0);
        //实例化ContentAdapter2类，并传入实现类
        ac6mPhotoListview.setAdapter(contentAdapter2);
        setListViewHeightBasedONChildren(ac6mPhotoListview);
    }

    public static void setListViewHeightBasedONChildren(ListView listView) {
        ListAdapter listAdapter = listView.getAdapter();
        if (listAdapter == null) {
            return;
        }
        int totalHeight = 0;
        for (int i = 0; i < listAdapter.getCount(); i++) {
            View listItem = listAdapter.getView(i, null, listView);
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }
        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
        listView.setLayoutParams(params);
    }

    @Override
    public void takeCancel() {
        super.takeCancel();
    }

    @Override
    public void takeFail(TResult result, String msg) {
        super.takeFail(result, msg);
        Log.e("tag", "青岛地区--照片失败==" + msg);
        String logStr = "\n" + "青岛地区--照片----拍照失败==" + "\n" + msg;
        PDALogUtils.createLogFile(0, logStr.getBytes());
        ArrayList<TImage> images = result.getImages();
        if (images != null && images.size() > 0) {
            String photo_file_path = images.get(0).getCompressPath();
            String photo_file_path2 = images.get(0).getOriginalPath();
            Log.e("tag", "青岛地区--照片拍照失败--path==" + photo_file_path);
            Log.e("tag", "青岛地区--照片拍照失败--path=22=" + photo_file_path2);
        }
    }

    //    String photo_file_path;
    String photo_file_path_OriginalPath;
    int FLAG = 1;//0:拍照   1：相册
    private List<String> flagImagesUrls = new ArrayList<>();
    private List<Integer> flagImagesUrlsPosition = new ArrayList<>();

    @Override
    public void takeSuccess(TResult result) {
        super.takeSuccess(result);
        if (result != null) {
            ArrayList<TImage> images = result.getImages();
            if (images != null && images.size() > 0) {
                //压缩后的图片路径，不压缩为null
//                photo_file_path = images.get(0).getCompressPath();
                Log.e("tag", "青岛地区--照片拍照成功--path=111=" + images.get(0).getOriginalPath());
                Log.e("tag", "青岛地区--照片拍照成功--path=Environment=" + Environment.getExternalStorageDirectory());
                ///storage/emulated/0
                if (FLAG == 1) {
                    //拍照
                    if (SystemUtil.getSystemModel().contains("GIONEE") || SystemUtil.getSystemModel().contains("gionee")) {
                        //金立手机的路线
                        photo_file_path_OriginalPath = Environment.getExternalStorageDirectory() + images.get(0)
                                .getOriginalPath().replace("my_images/", "").replace(external_path2, "");
                        Log.e("tag", "青岛地区--照片拍照成功-金立手机-path=22=" + photo_file_path_OriginalPath);
                    } else {
                        //其他手机
                        /***
                         * @question 拍照返回的照片的路径处理
                         * @method 有的手机返回的照片带有/storage/emulated/0，
                         * @method 有的不带，所以需要分别处理
                         * @import 找个地方划重点，考试要考的，TDM CD
                         */
                        if (images.get(0).getOriginalPath().contains("storage/emulated")) {
                            photo_file_path_OriginalPath = images.get(0).getOriginalPath().replace("my_images/", "").replace(external_path2, "");
                        } else {
                            photo_file_path_OriginalPath = Environment.getExternalStorageDirectory() + images.get(0)
                                    .getOriginalPath().replace("my_images/", "").replace(external_path2, "");
                        }
//                    photo_file_path_OriginalPath = Environment.getExternalStorageDirectory() + images.get(0)
//                            .getOriginalPath().replace("my_images/", "");
                        Log.e("tag", "青岛地区--照片拍照成功--path=22=" + photo_file_path_OriginalPath);
                    }
                } else {
                    //相册
                    photo_file_path_OriginalPath = images.get(0)
                            .getOriginalPath().replace("my_images/", "").replace(external_path2, "");
                    Log.e("tag", "青岛地区--照片相册--path=2234343434=" + photo_file_path_OriginalPath);
                }
//                //原图片的路径
//                photo_file_path_OriginalPath = Environment.getExternalStorageDirectory() + images.get(0)
//                        .getOriginalPath().replace("my_images/", "");
//                Log.e("tag", "拍照成功--path=22=" + photo_file_path_OriginalPath);
                if (!TextUtils.isEmpty(photo_file_path_OriginalPath)) {
                    //拍照不需要编辑的
                    if (isYasuoPhoto.equals("是")) {
                        Luban.with(instances)
                                .load(new File(photo_file_path_OriginalPath))                     //传人要压缩的图片
                                .setCompressListener(new OnCompressListener() { //设置回调
                                    @Override
                                    public void onStart() {
                                        // TODO 压缩开始前调用，可以在方法内启动 loading UI
                                    }

                                    @Override
                                    public void onSuccess(File file) {
                                        // TODO 压缩成功后调用，返回压缩后的图片文件
                                        Log.e("tag", "青岛地区--照片压缩成功后调用");
                                        //拍照压缩后上传
                                        getDataUploadPhoto(file, photo_file_path_OriginalPath);
                                    }

                                    @Override
                                    public void onError(Throwable e) {
                                        // TODO 当压缩过程出现问题时调用
                                        Toast.makeText(instances, "青岛地区--照片图片压缩出现问题，请重试", Toast.LENGTH_LONG).show();
                                    }
                                }).launch();    //启动压缩
                    } else {
                        getDataUploadPhoto(new File(photo_file_path_OriginalPath), photo_file_path_OriginalPath);
                    }

                }
            }
        }
    }

    TypeModel typeModel;
    int TypeModel_Position = 0;
    String img_imageUri_path;

    Wai_6M_PhotoAdapter.MyClickListener mListener = new Wai_6M_PhotoAdapter.MyClickListener() {
        @Override
        public void myOnClick(int position, View v, int flag) {
            PHOTO_TYPE = typeModelListAdapter.get(position).getCode();
            TypeModel_Position = position;
            FLAG = flag;
            typeModel = new TypeModel();
            typeModel.setName(typeModelListAdapter.get(position).getName());
            typeModel.setCode(typeModelListAdapter.get(position).getCode());
            if (position == 0) {
                getDataDCPicture("QD110");
            } else if (position == 1) {
                getDataDCPicture("QD111");
            }
        }
    };
    //    TypeModel typeModel;
//    int TypeModel_Position = 0;
//    private String img_imageUri_path;
//    private ContentAdapter2.MyClickListener mListener = new ContentAdapter2.MyClickListener() {
//        @Override
//        public void myOnClick(int position, View v, int flag) {
//            PHOTO_TYPE = typeModelListAdapter.get(position).getCode();
//            TypeModel_Position = position;
//            FLAG = flag;
//            if (flag == 0) {
////                //跳转到图片预览界面
////                if (WAIJIAN_PHOTO_PREVIEW_LISTS.get(Integer.parseInt(PHOTO_TYPE)) != null) {
////                    Intent intent_preview = new Intent(instances, PhotoPreviewActivity.class);
////                    intent_preview.putExtra("key_integer", Integer.parseInt(PHOTO_TYPE));
////                    startActivity(intent_preview);
////                }
//
//                //相册
//                takePhoto = getTakePhoto();
//                File file = new File(Environment.getExternalStorageDirectory(), external_path + "/temp_my_app/" + System
//                        .currentTimeMillis() + ".jpg");
//                if (!file.getParentFile().exists()) {
//                    file.getParentFile().mkdirs();
//                }
//                imageUri = Uri.fromFile(file);
//                UtilsLog.e("photo", "WAIJIAN_PHOTO_imageUri=7777=" + imageUri);
//                img_imageUri_path = imageUri.getPath();
//                UtilsLog.e("photo", "WAIJIAN_PHOTO_imageUri=888=" + imageUri.getPath());
//                takePhoto.onPickFromDocuments();
//                typeModel = new TypeModel();
//                typeModel.setName(typeModelListAdapter.get(position).getName());
//                typeModel.setCode(typeModelListAdapter.get(position).getCode());
//
//
//            } else if (flag == 1) {
////                takePicture();
////                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
////                    takePicture();
////                } else {
//                Log.e("photo", "takePhoto---takePhoto");
//                takePhoto = getTakePhoto();
//                TakePhotoOptions takePhotoOptions = new TakePhotoOptions.Builder().setCorrectImage(false).create();
//                takePhoto.setTakePhotoOptions(takePhotoOptions);
////                    configCompress(takePhoto);
////                    File file = new File(Environment.getExternalStorageDirectory(), "/temp_my_app/" + System
////                            .currentTimeMillis() + ".jpg");
//                File file = new File(Environment.getExternalStorageDirectory(), external_path + "/temp_my_app/" + System
//                        .currentTimeMillis() + ".jpg");
//                if (!file.getParentFile().exists()) {
//                    file.getParentFile().mkdirs();
//                }
//                imageUri = Uri.fromFile(file);
//                UtilsLog.e("photo", "WAIJIAN_PHOTO_imageUri=7777=" + imageUri);
//                img_imageUri_path = imageUri.getPath();
//                UtilsLog.e("photo", "WAIJIAN_PHOTO_imageUri=888=" + imageUri.getPath());
//                takePhoto.onPickFromCapture(imageUri);
////                }
//                typeModel = new TypeModel();
//                typeModel.setName(typeModelListAdapter.get(position).getName());
//                typeModel.setCode(typeModelListAdapter.get(position).getCode());
//            } else if (flag == 2) {
////                //跳转到图片预览界面
//                if (WAIJIAN_PHOTO_PREVIEW_LISTS.get(PHOTO_TYPE) != null) {
//                    Intent intent_preview = new Intent(instances, PhotoPreviewActivity.class);
//                    intent_preview.putExtra("key_integer", PHOTO_TYPE);
//                    startActivity(intent_preview);
//                }
//            }
//        }
//    };
    String img_code = "";

    //上传照片
    private void getDataUploadPhoto(final File file, final String file_name) {
        UtilsLog.e("青岛地区--照片getDataUploadPhoto---url==" + SharedPreferencesUtils.getFileIP(instances) + UPLOAD_PHOTO);
        String QueueID = "", GUID = "", Times = "",
                PlatformSN = "", SN = "", PhotoDate = "",
                PhotoType = "", Type = "", CarNO = "",
                PlateType = "",
                VIN = "", FileType = "jpg";
        if (flag == 0) {
            QueueID = carsInforModel.getQueueID();
            GUID = carsInforModel.getGUID();
            Times = carsInforModel.getTimes();
            PlatformSN = carsInforModel.getPlatformSN();
            SN = carsInforModel.getSN();
            PhotoDate = DateUtil.currentTime2();
            PhotoType = PHOTO_TYPE;
            Type = carsInforModel.getType();
            CarNO = carsInforModel.getPlateRegion() +
                    carsInforModel.getPlateNO();
            PlateType = carsInforModel.getPlateType();
            VIN = carsInforModel.getVIN();
        } else if (flag == 1) {
            QueueID = String.valueOf(recheckCarsModel.getQueueID());
            GUID = recheckCarsModel.getGUID();
            Times = String.valueOf(recheckCarsModel.getTimes());
            PlatformSN = recheckCarsModel.getPlatformSN();
            SN = recheckCarsModel.getSN();
            PhotoDate = DateUtil.currentTime2();
            PhotoType = PHOTO_TYPE;
            Type = recheckCarsModel.getType();
            CarNO = recheckCarsModel.getPlateRegion() +
                    recheckCarsModel.getPlateNO();
            PlateType = recheckCarsModel.getPlateType();
            VIN = recheckCarsModel.getVIN();
        }

        String str = "QueueID:" + QueueID + "\n" +
                "GUID:" + GUID + "\n" +
                "Times:" + Times + "\n" +
                "PlatformSN:" + PlatformSN + "\n" +
                "SN:" + SN + "\n" +
                "PhotoDate:" + PhotoDate + "\n" +
                "PhotoType:" + PhotoType + "\n" +
                "Type:" + Type + "\n" +
                "CarNO:" + CarNO + "\n" +
                "PlateType:" + PlateType + "\n" +
                "ItemCode:" + Item_Code + "\n" +
                "Line:" + Line + "\n" +
                "VIN:" + VIN + "\n" +
                "FileType:" + FileType + "\n";
        UtilsLog.e("青岛地区--照片getDataUploadPhoto---json==" + str);
        String logStr = "\n" + "青岛地区--照片---json==" +
                "\n" + "json::" + str + "\n";
        PDALogUtils.createLogFile(0, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getFileIP(instances) + UPLOAD_PHOTO).tag(instances)
//                .params("PHOTO_TYPE", PHOTO_TYPE)
                //guid
                .params("QueueID", QueueID)
                //guid
                .params("GUID", GUID)
                //次数
                .params("Times", Times)
                //PlatformSN
                .params("PlatformSN", PlatformSN)
                //SN
                .params("SN", SN)
                //拍摄时间
                .params("PhotoDate", DateUtil.currentTime2())
                //照片类型-拍的哪里的照片，位置
                .params("PhotoType", PHOTO_TYPE)
                //车辆类型
                .params("Type", Type)
                //车牌号码，两个拼起来的
                .params("CarNO", carNo)
                //号牌类型
                .params("PlateType", PlateType)
                //拍照code F1表示外检
                .params("ItemCode", Item_Code)
                //外检车道，检测线代号
                .params("Line", Line)
                //车辆识别代码
                .params("VIN", VIN)
                .params("FileType", "jpg")
//                .params("FileType", FileUtils.getExtensionName(file.getName()))
                //照片
                .params("zp", file)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getDataUploadPhoto-result==" + result);
                        String logStr = "\n" + "青岛地区--照片--请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getFileIP(instances) +
                                UPLOAD_PHOTO + "\n" + "result:" + response.body();
                        PDALogUtils.createLogFile(0, logStr.getBytes());
//                        UtilsLog.e("response.headers()-result==" + response.headers());
//                        photo_result(PHOTO_TYPE);
//                        if (PHOTO_TYPE != null) {
//                            WAIJIAN_PHOTO_PREVIEW_LISTS.put(Integer.parseInt(PHOTO_TYPE), file);
//                        }
//                        WAIJIAN_PHOTO_PREVIEW_LISTS.put(Integer.parseInt(PHOTO_TYPE), file);
                        WAIJIAN_PHOTO_PREVIEW_LISTS.put(PHOTO_TYPE, file);
                        if (!TextUtils.isEmpty(result) && !"[[]]".equals(result) && !"[{}]".equals(result)
                                && !"[]".equals(result)) {
                            String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\",
                                    "");
                            UtilsLog.e("getDataUploadPhoto-newResult==" + newResult);
                            if ("ok".equalsIgnoreCase(newResult)) {
                                Toast.makeText(instances, "上传成功", Toast.LENGTH_LONG).show();
                                typeModel.setColor(1);
                                typeModelListAdapter.set(TypeModel_Position, typeModel);
                                contentAdapter2.notifyDataSetChanged();
                            } else {
                                Toast.makeText(instances, "上传失败，请重新拍照", Toast.LENGTH_LONG).show();
                            }
                        } else {
                            UtilsLog.e("青岛地区--照片getDataUploadPhoto-result==" + "没有数据");
                        }
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("青岛地区--照片getDataUploadPhoto-onError==" + response.body());
                        UtilsLog.e("青岛地区--照片getDataUploadPhoto-onError==" + response.getException());
                        String logStr = "\n" + "青岛地区--照片-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getFileIP(instances) +
                                UPLOAD_PHOTO + "\n" + "result:" + response.body() + "\n" +
                                response.getException() + "\n" + response.message();
                        PDALogUtils.createLogFile(0, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);

                        Toast.makeText(instances, "上传照片失败，请重试", Toast.LENGTH_LONG).show();
                    }
                });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkGo.getInstance().cancelTag(this);
        instances = null;
    }

    @OnClick({R.id.ac_6m_photo_ib_back_qingdao, R.id.ac_6m_photo_btn_other_imags_qingdao,
            R.id.ac_6m_photo_btn_buhege2_qingdao, R.id.ac_6m_photo_btn_wancheng2_qingdao, R.id.ac_wai_6m_line_qingdao})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ac_wai_6m_line_qingdao:
                pop_xuhao.showAsDropDown(acWai6mLine);
                break;
            case R.id.ac_6m_photo_ib_back_qingdao:
                finish();
                break;
            case R.id.ac_6m_photo_btn_other_imags_qingdao:
                break;
            case R.id.ac_6m_photo_btn_buhege2_qingdao:
                break;
            case R.id.ac_6m_photo_btn_wancheng2_qingdao:
                break;
        }
    }

    private String[] line_str = new String[]{"1", "2", "3", "4", "5", "6"};

    //popuwindow
    private View popu_xuhao_view;
    private LinearLayout parent22;
    private PopupWindow pop_xuhao = null;
    private ListView listview_xuhao;
    private MyProvincesListAdapter2 myProAdapter;
    private List<String> xuhaoList = new ArrayList<String>();

    private void pop_xuhao() {
        for (int i = 0; i < Constants.WAIJIAN_CHEDAO_CHEJIAN_XIANHAO.length; i++) {
            xuhaoList.add(i, Constants.WAIJIAN_CHEDAO_CHEJIAN_XIANHAO[i]);
        }
        pop_xuhao = new PopupWindow(this);
        popu_xuhao_view = getLayoutInflater().inflate(R.layout.item_setting_province_letter,
                null);
        pop_xuhao.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        pop_xuhao.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        pop_xuhao.setBackgroundDrawable(new BitmapDrawable());
        pop_xuhao.setFocusable(true);
        pop_xuhao.setOutsideTouchable(true);
        pop_xuhao.setContentView(popu_xuhao_view);
        parent22 = (LinearLayout) popu_xuhao_view.findViewById(R.id.setting_provinces_parent);
        listview_xuhao = (ListView) popu_xuhao_view.findViewById(R.id.setting_provinces_listview2);
        myProAdapter = new MyProvincesListAdapter2(this, xuhaoList);
        listview_xuhao.setAdapter(myProAdapter);
        listview_xuhao.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1,
                                    int position, long arg3) {
                acWai6mLine.setText(xuhaoList.get(position));
                Line = xuhaoList.get(position);
                pop_xuhao.dismiss();
            }
        });
        parent22.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                pop_xuhao.dismiss();
            }
        });
    }


    //动态拍照
    String jsonStr_getDataDCPicture;

    private void getDataDCPicture(String plateType) {
        String logStr = "\n" + "------青岛地区--拍照请求接口调用-----" + "\n";
        PDALogUtils.createLogFile(0, logStr.getBytes());
        String QueueID = "", GUID = "", Times = "",
                PlatformSN = "", SN = "", PhotoDate = "",
                PhotoType = "", Type = "", CarNO = "",
                PlateType = "", Detection_ID = "",
                VIN = "", FileType = "jpg";
        if (flag == 0) {
            QueueID = carsInforModel.getQueueID();
            GUID = carsInforModel.getGUID();
            Times = carsInforModel.getTimes();
            PlatformSN = carsInforModel.getPlatformSN();
            SN = carsInforModel.getSN();
            PhotoDate = DateUtil.currentTime2();
            PhotoType = PHOTO_TYPE;
            Type = carsInforModel.getType();
            CarNO = carsInforModel.getPlateRegion() +
                    carsInforModel.getPlateNO();
            PlateType = carsInforModel.getPlateType();
            VIN = carsInforModel.getVIN();
            Detection_ID = String.valueOf(carsInforModel.getID());
        } else if (flag == 1) {
            QueueID = String.valueOf(recheckCarsModel.getQueueID());
            GUID = recheckCarsModel.getGUID();
            Times = String.valueOf(recheckCarsModel.getTimes());
            PlatformSN = recheckCarsModel.getPlatformSN();
            SN = recheckCarsModel.getSN();
            PhotoDate = DateUtil.currentTime2();
            PhotoType = PHOTO_TYPE;
            Type = recheckCarsModel.getType();
            CarNO = recheckCarsModel.getPlateRegion() +
                    recheckCarsModel.getPlateNO();
            PlateType = recheckCarsModel.getPlateType();
            VIN = recheckCarsModel.getVIN();
            Detection_ID = String.valueOf(recheckCarsModel.getQueueID());
        }


        PictureModel model = new PictureModel();
        model.setItemCode("F3");
        model.setLine(acWai6mLine.getText().toString().trim());
        model.setGUID(GUID);
        model.setPhotoDate(DateUtil.currentTime2());
        model.setPhotoType(plateType);
        model.setPlateNO(CarNO);
        model.setPlatformSN(PlatformSN);
        model.setTest_times(Times);
        model.setTimes(Times);
        model.setVIN(VIN);
        model.setPlateType(PlateType);
        model.setDetection_ID(Detection_ID);
        Gson gson = new Gson();
        jsonStr_getDataDCPicture = gson.toJson(model);
        UtilsLog.e("getDataDCPicture---jsonStr==" + jsonStr_getDataDCPicture);
        String url_ip = "";
        if (!TextUtils.isEmpty(SharedPreferencesUtils.getIP(QingDaoPhotoActivity.this))
                && SharedPreferencesUtils.getIP(QingDaoPhotoActivity.this) != "") {
            url_ip = SharedPreferencesUtils.getIP(QingDaoPhotoActivity.this);
        } else {

        }
        String logStr123 = "\n" + "青岛地区--JSON==" +
                "\n" + "URL::" + url_ip + DC_PICTURE +
                "\n" + "JSON::" + jsonStr_getDataDCPicture + "\n";
        PDALogUtils.createLogFile(0, logStr123.getBytes());
        UtilsLog.e("getDataDCPicture---url==" + url_ip + DC_PICTURE);
        OkGo.<String>post(url_ip + DC_PICTURE).tag(QingDaoPhotoActivity.this)
                .upJson(jsonStr_getDataDCPicture)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getDataDCPicture-result==" + result);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getDataDCPicture-newResult==" + newResult);

                        String logStr = "\n" + "青岛地区--拍照请求成功==" +
                                "\n" + "URL::" + DC_PICTURE +
                                "\n" + "JSON::" + jsonStr_getDataDCPicture + "\n" +
                                "result::" + result;
                        PDALogUtils.createLogFile(0, logStr.getBytes());
//                        Toast.makeText(instances, "拍照成功", Toast
//                                .LENGTH_LONG).show();
                        if ("ok".contains(result) || "ok".contains(newResult)) {
                            Toast.makeText(instances, "拍照成功", Toast
                                    .LENGTH_LONG).show();
                            typeModel.setColor(1);
                            typeModelListAdapter.set(TypeModel_Position, typeModel);
                            contentAdapter2.notifyDataSetChanged();
                        } else {
                            Toast.makeText(instances, "拍照失败，请重试", Toast
                                    .LENGTH_LONG).show();
                        }
//                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
//                                (newResult) && !"[]".equals(newResult)) {
////                            if ("ok".contains(result) || "ok".contains(newResult)) {
//                                Toast.makeText(instances, "拍照成功", Toast
//                                        .LENGTH_LONG).show();
////                            } else {
////                                Toast.makeText(instances, "拍照失败，请重试", Toast
////                                        .LENGTH_LONG).show();
////                            }
//                        } else {
//                            UtilsLog.e("getDataDCPicture-result==" + "没有数据");
//                        }
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataDCPicture-onError==" + response.body());
                        String logStr = "\n" + "青岛地区--拍照请求失败" +
                                "\n" + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(0, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

}
